package com.zy.qudadid.presenter;

import com.zy.bean.Users;
import com.zy.qudadid.model.Res;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.network.Net;
import com.zy.qudadid.presenter.base.BasePresenterImp;
import com.zy.qudadid.ui.view.OwnYijianView;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ninos on 2016/7/29.
 */
public class OwnYijianPresenter extends BasePresenterImp<OwnYijianView> {
//    c=infoOrderCar&a=getpeopleinfo
    public void getpeopleinfo(String data) {
        Subscription subscription = Net.getService()
                .getpeopleinfo("infoOrderCar", "getpeopleinfo", data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res<Users>>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.error();
                    }

                    @Override
                    public void onNext(Res<Users> res) {
                        if (res.code == Const.OK) {
                            view.success(res.datas);
                        } else {
                            view.error();
                        }
                    }
                });

        addSubscription(subscription);
    }

//    c=user&a=complaint&args=
public void complaint(String data) {
    Subscription subscription = Net.getService()
            .complaint(data)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Subscriber<Res>() {

                @Override
                public void onCompleted() {
                }

                @Override
                public void onError(Throwable e) {
                    view.errorc();
                }

                @Override
                public void onNext(Res res) {
                    if (res.code == Const.OK) {
                        view.successc();
                    } else {
                        view.errorc();
                    }
                }
            });

    addSubscription(subscription);
}
}
